/**
 *  污染源数据造假识别-柱状图检验
 *  Created by dinghh on 2018/7/13.
 */
'use strict';
angular.module("MetronicApp").directive('testBar', function () {
    return {
        scope: {
            id: "@",
            data: "="
        },
        restrict: 'EA',
        template: '<div style="height:300px;width:600px;margin: 0 auto;"></div>',
        replace: true,
        link: function ($scope, element, attrs, controller) {
            function getOption(data) {
                var option = {
                    grid: {
                        top: '2%',
                        left: 0,
                        right: '6%',
                        bottom: '10%',
                        containLabel: true
                    },
                    xAxis : [
                        {
                            type : 'category',
                            data : ['超标检验', '波动检验', '箱体检验', '零值检验', '工况检验']
                        }
                    ],
                    yAxis : [
                        {
                            type : 'value',
                            min: 0,
                            max: 100,
                            name: '分'
                        }
                    ],
                    series : [
                        {
                            type:'bar',
                            barWidth: '70%',
                            data:[70, 85, 58, 62, 85],
                            itemStyle:{
                                normal:{
                                    color:function(params){
                                        var colorList =['#2ec7c9','#e06666','#ffb980','#ffb980','#d87a80'];
                                        return colorList[params.dataIndex]
                                    },
                                    barBorderRadius:5
                                }
                            }
                        }
                    ]
                };
                return option;
            }

            $scope.$watch('data', function (newVal, oldVal) {
                var myChart = echarts.init(document.getElementById($scope.id), 'macarons');
                myChart.setOption(getOption(newVal));
            });
        }
    };
});
